package ru.resumeService.web.servlet;

import ru.resumeService.service.ResumeService;
import ru.resumeService.service.impl.ResumeServiceImpl;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.sql.SQLException;

public class Delete extends HttpServlet {

    ResumeService resumeService = new ResumeServiceImpl();

    public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException {
        resumeService = new ResumeServiceImpl();
        int id = Integer.parseInt(request.getParameter("id"));
        try {
            resumeService.deleteResume(id);
        } catch (SQLException e) {
            e.printStackTrace();  //To change body of catch statement use File | Settings | File Templates.
        }
        RequestDispatcher dispatcher;
        dispatcher = request.getRequestDispatcher("/resumeList");
        if (dispatcher != null) {
            try {
                dispatcher.forward(request, response);
            } catch (ServletException e) {
                e.printStackTrace();  //To change body of catch statement use File | Settings | File Templates.
            }
        }

    }

    public void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException {
        response.setContentType("text/html; charset=UTF-8");
        response.setCharacterEncoding("UTF-8");
        request.setCharacterEncoding("UTF-8");


    }
}
